/**
 * 角色相关请求模块
 */

import request from '@/utils/request'

export const getQueryCourses = (data: any) => {
  return request({
    method: 'POST',
    url: '/boss//course/getQueryCourses',
    data: data
  })
}

export const changeState = (params: any) => {
  return request({
    method: 'GET',
    url: '/boss//course/changeState',
    params
  })
}

export const getCourseById = (courseId: number | string) => {
  return request({
    method: 'GET',
    url: '/boss//course/getCourseById',
    params: {
      courseId
    }
  })
}

export const uploadCourseImg = (
  data: any,
  onUploadProgress: (progressEvent: ProgressEvent<EventTarget>) => void
) => {
  return request({
    method: 'POST',
    url: '/boss//course/upload',
    data,
    // h5新增的上传响应事件 progress
    onUploadProgress
  })
}

export const saveOrUpdate = (data: any) => {
  return request({
    method: 'POST',
    url: '/boss//course/saveOrUpdateCourse',
    data: data
  })
}

export const getSectionAndLesson = (courseId: string | number) => {
  return request({
    method: 'GET',
    url: '/boss//course/section/getSectionAndLesson',
    params: {
      courseId
    }
  })
}

export const saveOrUpdateSection = (data: any) => {
  return request({
    method: 'POST',
    url: '/boss//course/section/saveOrUpdateSection',
    data
  })
}

export const saveOrUpdateLesson = (data: any) => {
  return request({
    method: 'POST',
    url: '/boss//course/lesson/saveOrUpdate',
    data
  })
}

export const getAllResource = () => {
  return request({
    method: 'GET',
    url: '/boss/resource/getAll'
  })
}

export const getRoleResource = (roleId: number | string) => {
  return request({
    method: 'GET',
    url: '/boss/resource/getRoleResources',
    params: { roleId }
  })
}

export const allocateRoleResources = (data: any) => {
  return request({
    method: 'POST',
    url: '/boss/resource/allocateRoleResources',
    data
  })
}
